package cn.zebra.dev.other.module.ordersBarter.service.impl;

import cn.zebra.dev.ibatis.plus.service.impl.ServiceImpl;
import cn.zebra.dev.ibatis.plus.utils.PageUtils;
import cn.zebra.dev.ibatis.plus.utils.Query;
import cn.zebra.dev.other.module.ordersBarter.dao.OrdersBarterDao;
import cn.zebra.dev.other.module.ordersBarter.entity.OrdersBarterEntity;
import cn.zebra.dev.other.module.ordersBarter.service.OrdersBarterService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 
 *
 * @author runnable
 */
@Service
public class OrdersBarterServiceImpl extends ServiceImpl<OrdersBarterDao, OrdersBarterEntity> implements OrdersBarterService {

    @Override
    public PageUtils<OrdersBarterEntity> findPage(Map<String, Object> params) {
        QueryWrapper<OrdersBarterEntity> wrapper = new QueryWrapper<>();
        IPage<OrdersBarterEntity> page = this.page(
                new Query<OrdersBarterEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils<>(page);
    }

    @Override
    public PageUtils<OrdersBarterEntity> findPageByUserId(Map<String, Object> map) {
        QueryWrapper<OrdersBarterEntity> wrapper = new QueryWrapper<>();
        wrapper.apply("user_id = {0}",map.get("userId"));
        if(map.get("state") != null){
            wrapper.apply(map.containsKey("state"),"state = {0}",map.get("state"));
        }
        IPage<OrdersBarterEntity> page = this.page(
                new Query<OrdersBarterEntity>(map).getPage(),
                wrapper
        );
        return new PageUtils<>(page);
    }

    @Override
    public PageUtils<OrdersBarterEntity> findPageByShopId(Map<String, Object> map) {
        QueryWrapper<OrdersBarterEntity> wrapper = new QueryWrapper<>();
        wrapper.apply("shop_id = {0}",map.get("shopId"));
        if(map.get("state") != null){
            wrapper.apply(map.containsKey("state"),"state = {0}",map.get("state"));
        }
        IPage<OrdersBarterEntity> page = this.page(
                new Query<OrdersBarterEntity>(map).getPage(),
                wrapper
        );
        return new PageUtils<>(page);
    }

}
